package cn.ld.module.system.dal.mapper.tenant;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.system.controller.admin.tenant.vo.tenant.TenantPageInVO;
import cn.ld.module.system.dal.entity.tenant.TenantEntity;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 租户 Mapper
 *
 * @author 蓝盾
 */
@Mapper
public interface TenantMapper extends BaseMapperX<TenantEntity> {

    default PageResult<TenantEntity> selectPage(TenantPageInVO inVO) {
        return selectPage(inVO, new LambdaQueryWrapperX<TenantEntity>()
                .likeIfPresent(TenantEntity::getName, inVO.getName())
                .likeIfPresent(TenantEntity::getContactName, inVO.getContactName())
                .likeIfPresent(TenantEntity::getContactMobile, inVO.getContactMobile())
                .eqIfPresent(TenantEntity::getStatus, inVO.getStatus())
                .betweenIfPresent(TenantEntity::getCreateTime, inVO.getCreateTime())
                .orderByDesc(TenantEntity::getId));
    }

    default TenantEntity selectByName(String name) {
        return selectOne(TenantEntity::getName, name);
    }

    default TenantEntity selectByWebsite(String website) {
        return selectOne(TenantEntity::getWebsite, website);
    }

    default Long selectCountByPackageId(Long packageId) {
        return selectCount(TenantEntity::getPackageId, packageId);
    }

    default List<TenantEntity> selectListByPackageId(Long packageId) {
        return selectList(TenantEntity::getPackageId, packageId);
    }

}
